home *** CD-ROM | disk | FTP | other *** search
- /* LaunchWithDoc */
- /* The smallest LaunchAplication example I could come up with. */
- /* this launches an application with a 'odoc' event */
- /* this little bit of code here uses two Standard File calls to get */
- /* the doc to launch and the file to launch with, you will of course */
- /* want to replace these with whatever you want to do */
- /* ••• NOTE: Thsi also works for launching non-System 7 applications. */
- /* If the Finder™ sees an 'odoc' or 'pdoc' Apple event in the launch block */
- /* and the application being launched is NOT system 7 aware, the Finder */
- /* coerces the Apple event into puppetstrings. So you */
- /* don't need to special case for non-7.0 applications. */
- /* Pretty neat, huh? */
- /* ••• Important: I'm not doing any error checking, you of course should */
- /* so your users don't hunt you down and burn your keyboard. */
- /* C.K. Haun */
- /* DTS */
- #include <Dialogs.h>
- #include <QuickDraw.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <Fonts.h>
- #include <appleevents.h>
- #include <processes.h>
- #include <files.h>
- #include <StandardFile.h>
- #include <Aliases.h>
-
- main()
- {
-
- FSSpec l1,f1; /* file spec for the app (l1) and the file (f1) */
- LaunchParamBlockRec launchThis;
- AEDesc myAddress;
- AEDesc docDesc,launchDesc;
- AEDescList theList;
- AliasHandle withThis;
- StandardFileReply myReply;
- AppleEvent theEvent;
-
-
-
- InitGraf((Ptr)&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- /* get the app to launch */
- StandardGetFile(nil,
- -1,
- nil,
- &myReply);
- if(!myReply.sfGood)return;
- l1=myReply.sfFile;
- launchThis.launchAppSpec=&l1;
-
- /* get the file to pass */
- StandardGetFile(nil,
- -1,
- nil,
- &myReply);
- if(!myReply.sfGood)return;
-
- /* the caller may have already done this, but it doesn't hurt to do it again */
- f1=myReply.sfFile;
- /* create an appleevent to carry it */
- AECreateAppleEvent(kCoreEventClass,kAEOpenDocuments,&myAddress,kAutoGenerateReturnID, kAnyTransactionID,&theEvent);
- /* create a list for the alaises. In this case, I only have one, but you still need */
- /* a list */
- AECreateList(nil,
- 0,
- false,
- &theList);
- /* create an alias out of the file spec */
- /* I'm not real sure why I did this, since there is a system coercion handler for */
- /* alias to FSSpec, but I'm paranoid */
- NewAlias(nil,&f1,&withThis);
- HLock((Handle)withThis);
- /* now create an alias descriptor */
- AECreateDesc(typeAlias,(Ptr)*withThis,GetHandleSize((Handle)withThis),&docDesc);
- HUnlock((Handle)withThis);
- /* put it in the list */
- AEPutDesc(&theList,0,&docDesc);
- AEPutParamDesc (&theEvent, keyDirectObject, &theList);
- /* coerce the event from being an event into being appParms */
- AECoerceDesc (&theEvent, typeAppParameters, &launchDesc);
- HLock((Handle)theEvent.dataHandle);
- /* and stuff it in the parameter block */
- /* This may look a little weird, since we're actually moving the evetn out of the */
- /* AppParameters descriptor. But it's necessary, the coercison to typeAppParameters */
- /* takes the 'aevt' and puts it all in one handle, instead of */
- /* leaving it as a AEDesc. So, only one handle is being added to */
- /* the launch parameter block instead of an AEDesc */
- launchThis.launchAppParameters=(AppParametersPtr)*(launchDesc.dataHandle);
- /* launch the thing */
- launchThis.launchBlockID = extendedBlock;
- launchThis.launchEPBLength = extendedBlockLen;
- launchThis.launchFileFlags=nil;
- launchThis.launchControlFlags= launchContinue + launchNoFileFlags ;
- LaunchApplication(&launchThis);
- /* and launch it */
-
-
-
- }
-
-